 #include"logger.h"
 #include<stdlib.h>
 #include<fcntl.h>
 #include<string.h>

 #include<sstream>

 
 Logger::Logger()
 {
   if(!getenv("LOG_LEVEL") || (getenv("LOG_LEVEL")!="[INFO]" || getenv("LOG_LEVEL")!="[ERROR]" || getenv("LOG_LEVEL")!="[DEBUG]" || getenv("LOG_LEVEL")!="[FATAL]"))
   {
      logLevel_ = INFO; 
   }else
   {  // for if 圈复杂度，
     logLevel_ = LogLevelType[getenv("LOG_LEVEL")];//把日志级别通过export保持在环境变量中,然后通过getenb来获取环境变量.
   }
    LogToTerminal_ = true;
    LogToLogfile_ = true;
  
 }
Logger& Logger::GetInstance()
 {
    static Logger logger;
    return logger;
 }
 void Logger::SetLogToTermianl(bool logToTerminal)
 {
    LogToTerminal_ = logToTerminal;
 }
 bool Logger::GetLogToTerminal()const
 {
    return LogToLogfile_;
 }
 void Logger::SetLogTOLogfile(bool logToLogfile)
 {
    LogToLogfile_ = logToLogfile;
 }
 bool Logger::GetLogToLogfile() const
 {
    return LogToLogfile_;
 }

 void Logger::SetLogFileName(const std::string& logFileName )
 {
    if(FileStream_.is_open())
    {
        FileStream_.close();
    }
     FileStream_.open(logFileName);
    LogToLogfile_ = true;
 }
 
 void Logger::SetLogLevel(LOG_LEVEL loglevel)
 {
   logLevel_ = loglevel;
 }
 LOG_LEVEL Logger::GetLogLevle()const
 {
   return logLevel_;
 }
 
